package com.whfc.iot.dust.processor;

import com.whfc.common.constant.QueueConst;
import com.whfc.common.enums.DevicePlatform;
import com.whfc.common.enums.DeviceType;
import com.whfc.common.util.JSONUtil;
import com.whfc.dust.entity.DustMsg;
import com.whfc.env.dto.AppDeviceDustLogDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class DustUpMsgProcessor0x03 implements DustUpMsgProcessor<DustMsg> {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private AmqpTemplate amqpTemplate;

    @Override
    public void processMsg(DustMsg reqMsg) {

        logger.info("处理dust数据,{}", reqMsg);

        AppDeviceDustLogDTO dustLogDTO = new AppDeviceDustLogDTO();
        dustLogDTO.setDeviceType(DeviceType.dust.getValue());
        dustLogDTO.setPlatform(DevicePlatform.jxct.name());
        dustLogDTO.setDeviceCode(reqMsg.getDeviceCode());
        dustLogDTO.setDeviceId(reqMsg.getDeviceId());
        dustLogDTO.setTime(new Date());
        dustLogDTO.setPm25(reqMsg.getPm25());
        dustLogDTO.setPm10(reqMsg.getPm10());
        dustLogDTO.setNoise(reqMsg.getNoise());
        dustLogDTO.setEnvTemp(reqMsg.getEnvTemp());
        dustLogDTO.setEnvRh(reqMsg.getEnvRh());
        dustLogDTO.setWindDirection(reqMsg.getWindDirection());
        dustLogDTO.setWindSpeed(reqMsg.getWindSpeed());
        dustLogDTO.setTsp(reqMsg.getTsp());
        dustLogDTO.setAtmos(reqMsg.getAtmos());
        //入消息队列
        String textMsg = JSONUtil.toString(dustLogDTO);
        try {
            amqpTemplate.convertAndSend(QueueConst.ENV_DUST_DATA, textMsg);
        } catch (Exception ex) {
            logger.error("", ex);
        }

    }
}
